import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class HoverStatus extends StatefulWidget {
  final Widget child;
  final VoidCallback onPressed;
  final Color defaultColor;
  final Color hoverColor;
  double radius;
  Color borderColor;
  HoverStatus(
      {required this.child,
      required this.onPressed,
      required this.defaultColor,
      required this.hoverColor,
      this.radius = 0,
      this.borderColor = Colors.transparent});

  @override
  _HoverStatusState createState() => _HoverStatusState();
}

class _HoverStatusState extends State<HoverStatus> {
  bool _isPressed = false;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTapDown: (_) {
        setState(() {
          _isPressed = true;
        });
      },
      onTapUp: (_) {
        Future.delayed(
            Duration(milliseconds: 200),
            () => {
                  if (mounted)
                    setState(() {
                      _isPressed = false;
                    })
                });
        widget.onPressed();
      },
      onTapCancel: () {
        setState(() {
          _isPressed = false;
        });
      },
      child: Container(
        decoration: BoxDecoration(
            color: _isPressed ? widget.hoverColor : widget.defaultColor,
            borderRadius: BorderRadius.all(Radius.circular(widget.radius)),
            border: Border.all(
                width: widget.borderColor == Colors.transparent ? 1.w : 0,
                color: widget.borderColor)),
        child: widget.child,
      ),
    );
  }
}
